package plateau;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Hashtable;
import java.util.Map;

import javax.imageio.ImageIO;


public class GlobalResources {

	private static Map<URL, Image> s_images;
	private URL m_imageFilename;
	public void setImageFilename(String imageFilename) throws IOException, URISyntaxException {
		if(s_images == null) {
			 s_images = new Hashtable<URL, Image>();
		}
		m_imageFilename = GlobalResources.class.getResource(imageFilename);
	}
	
	public Image getImage() throws IOException, URISyntaxException {
		if (m_imageFilename == null) {
			throw new IllegalArgumentException("GlobalResources:getImage() but the image filename is not setted !");
		}
		if (s_images.get(m_imageFilename) == null) {
			BufferedImage img = ImageIO.read(new File(m_imageFilename.toURI()));
			s_images.put(m_imageFilename, img);
		}
		return s_images.get(m_imageFilename);
	}

}
